classdef PredictionRiskViaSensitivityAnalysis ...
        < EmbeddedFeatureSelection ...
        & BinaryClassAlgorithm0able ... %%
        & Metricable %%
    %PREDICTIONRISKVIASENSITIVITYANALYSIS Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
    end
    
    methods
        function [ this ] = PredictionRiskViaSensitivityAnalysis( name )
            if nargin == 0
                this.setName('prediction_risk_via_sensitivity_analysis');
            end
            if nargin == 1
            end
        end
    end
    
    methods
        function [  ] = build( this, X1, Y1 )
            
            % Calculate the base ERR
            this.algorithm0.build(X1, Y1);
            result = this.algorithm0.apply(X1, Y1);
            error0 = 1 - this.metric.calc(Y1, result.Y_hat, result.Y_out);
            
            nFeature = size(X1, 2);
            zScore = zeros(1, nFeature);
            for iFeature = 1:nFeature
                % Calculate the ERR by replacing each feature by its mean
                X1_i = X1;
                X1_i(:, iFeature) = repmat(mean(X1(:, iFeature)), size(X1, 1), 1);
                result_i = this.algorithm0.apply(X1_i, Y1);
                error_i = 1 - this.metric.calc(Y1, result_i.Y_hat, result_i.Y_out);
                
                zScore(iFeature) = error_i - error0;
            end
            
            [this.model.zScore, this.model.zRank] = sort(zScore, 'descend');
        end
    end
    
end

